package com.welike.shibo.utils;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;

/**
 * @author fangyu
 * @version v1.0.0
 * @since 2019-08-20 01:19
 */
public class PasswordEncrypt {

    public static String encodeByMd5(String string) throws NoSuchAlgorithmException {
        // 确定计算方法
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        Base64.Encoder base64Encoder = Base64.getEncoder();
        // 加密字符串
        return base64Encoder.encodeToString(md5.digest(string.getBytes(StandardCharsets.UTF_8)));
    }

    public static void main(String[] args) throws NoSuchAlgorithmException {
        System.out.println(PasswordEncrypt.encodeByMd5("123456"));
    }
}
